package com.baizhi.service.impl;

import com.baizhi.dao.CmfzAlbumDao;
import com.baizhi.entity.CmfzAlbum;
import com.baizhi.service.CmfzAlbumService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
@Slf4j
@Service
@Transactional(readOnly = true)
public class CmfzAlbumServiceImpl implements CmfzAlbumService {
    @Autowired
    private CmfzAlbumDao cmfzAlbumDao;
    @Override
    public List<CmfzAlbum> selectAlbum(String type) {
        List<CmfzAlbum> list = new ArrayList<>();
        //根据接口文档  此处应有两个查询  一个获取最新的6条数据   一处获取所有
        if(type.equals("new")){
            //查询最新的6张专辑信息  这样用分页加排序查询
            Page<CmfzAlbum> cmfzAlbumPage = new Page<>(1, 6);//获取第一页的6条数据
            QueryWrapper<CmfzAlbum> queryWrapper = new QueryWrapper<>();
            queryWrapper.orderByDesc("album_date");//按时间降序  获取最新
            Page<CmfzAlbum> albumPage = cmfzAlbumDao.selectPage(cmfzAlbumPage, queryWrapper);
            list = albumPage.getRecords();
        }else if (type.equals("all")){
            //查询所有专辑信息
            list = cmfzAlbumDao.selectList(null);
        }
        return list;
    }

    @Override
    public CmfzAlbum selectById(int albumId) {
        return cmfzAlbumDao.selectById(albumId);
    }
}
